package com.sise.dubbo.service;

import com.sise.dubbo.api.UserRpcService;
import com.sise.dubbo.common.ServiceException;
import com.sise.dubbo.dto.PaginationRespDTO;
import com.sise.dubbo.dto.RpcRespDTO;
import com.sise.dubbo.model.User;
import com.sise.dubbo.vo.PageRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author hao_lin
 * @data 2018/9/29 13:47
 */
@Service
public class UserService {
    @Autowired
    private UserRpcService userRpcService;

    public String print(String str) {
        return userRpcService.printStr(str);
    }

    public PageRespVo<User> findAll(int page) {
        RpcRespDTO<PaginationRespDTO<User>> respDTORpcRespDTO = userRpcService.findAll(page);
        PageRespVo<User> userPageRespVo = new PageRespVo<>();
        userPageRespVo.setList(respDTORpcRespDTO.getData().getList());
        userPageRespVo.setTotal(respDTORpcRespDTO.getData().getTotal());
        return userPageRespVo;
    }

    public PageRespVo<User> findByUsername(String username, int page) throws ServiceException {
        RpcRespDTO<PaginationRespDTO<User>> respDTORpcRespDTO = userRpcService.findByUsername(username, page);
        PageRespVo<User> userPageRespVo = new PageRespVo<>();
        userPageRespVo.setList(respDTORpcRespDTO.getData().getList());
        userPageRespVo.setTotal(respDTORpcRespDTO.getData().getTotal());
        return userPageRespVo;
    }

}
